<!doctype html>


<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>keyhandler.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>





<div class="colmask rightmenu">
<div class="colleft">
    <div class="col1">
      <!-- Column 1 start -->

<div id="title">
       <span class="fn">keyhandler.js</span>
</div>

<div class="g-section g-tpl-75-25">
  <div class="g-unit g-first" id="description">
    This file contains a class for working with keyboard events
 that repeat consistently across browsers and platforms. It also unifies the
 key code so that it is the same in all browsers and platforms.

 Different web browsers have very different keyboard event handling. Most
 importantly is that only certain browsers repeat keydown events:
 IE, Opera, FF/Win32, and Safari 3 repeat keydown events.
 FF/Mac and Safari 2 do not.

 For the purposes of this code, &quot;Safari 3&quot; means WebKit 525+, when WebKit
 decided that they should try to match IE&#39;s key handling behavior.
 Safari 3.0.4, which shipped with Leopard (WebKit 523), has the
 Safari 2 behavior.

 Firefox, Safari, Opera prevent on keypress

 IE prevents on keydown

 Firefox does not fire keypress for shift, ctrl, alt
 Firefox does fire keydown for shift, ctrl, alt, meta
 Firefox does not repeat keydown for shift, ctrl, alt, meta

 Firefox does not fire keypress for up and down in an input

 Opera fires keypress for shift, ctrl, alt, meta
 Opera does not repeat keypress for shift, ctrl, alt, meta

 Safari 2 and 3 do not fire keypress for shift, ctrl, alt
 Safari 2 does not fire keydown for shift, ctrl, alt
 Safari 3 *does* fire keydown for shift, ctrl, alt

 IE provides the keycode for keyup/down events and the charcode (in the
 keycode field) for keypress.

 Mozilla provides the keycode for keyup/down and the charcode for keypress
 unless it&#39;s a non text modifying key in which case the keycode is provided.

 Safari 3 provides the keycode and charcode for all events.

 Opera provides the keycode for keyup/down event and either the charcode or
 the keycode (in the keycode field) for keypress events.

 Firefox x11 doesn&#39;t fire keydown events if a another key is already held down
 until the first key is released. This can cause a key event to be fired with
 a keyCode for the first key and a charCode for the second key.

 Safari in keypress

 charCode keyCode which
 ENTER:       13      13    13
 F1:       63236   63236 63236
 F8:       63243   63243 63243
 ...
 p:          112     112   112
 P:           80      80    80

 Firefox, keypress:

 charCode keyCode which
 ENTER:        0      13    13
 F1:           0     112     0
 F8:           0     119     0
 ...
 p:          112       0   112
 P:           80       0    80

 Opera, Mac+Win32, keypress:

 charCode keyCode which
 ENTER: undefined      13    13
 F1:    undefined     112     0
 F8:    undefined     119     0
 ...
 p:     undefined     112   112
 P:     undefined      80    80

 IE7, keydown

 charCode keyCode     which
 ENTER: undefined      13 undefined
 F1:    undefined     112 undefined
 F8:    undefined     119 undefined
 ...
 p:     undefined      80 undefined
 P:     undefined      80 undefined
  </div>
  

        <div class="g-unit" id="useful-links">
          <div class="title">Useful links</div>
          <ol>
            <li><a href="../demos/keyhandler.html">Demo</a></li>
            <li><a href="closure_goog_events_keyhandler.js.source.html"><span class='source-code-link'>Source Code</span></a></li>
          </ol>
        </div>
</div>

<h2 class="g-first">File Location</h2>
  <div class="g-section g-tpl-20-80">
    <div class="g-unit g-first">
      <div class="g-c-cell code-label">events/keyhandler.js</div>
    </div>
  </div>
<hr/>


  <h2>Classes</h2>
 <div class="fn-constructor">
        <a href="class_goog_events_KeyHandler.html">
          goog.events.KeyHandler</a><br/>
        <div class="class-details">A wrapper around an element that you want to listen to keyboard events on.
XXX: {Document|Element} != {Element|Document}.
see: <a href="http://b/1470354">http://b/1470354</a></div>
 </div>
 <div class="fn-constructor">
        <a href="class_goog_events_KeyEvent.html">
          goog.events.KeyEvent</a><br/>
        <div class="class-details">This class is used for the goog.events.KeyHandler.EventType.KEY event and
it overrides the key code with the fixed key code.</div>
 </div>
      
<br/>

  <div class="legend">
        <span class="key publickey"></span><span>Public</span>
        <span class="key protectedkey"></span><span>Protected</span>
        <span class="key privatekey"></span><span>Private</span>
  </div>





  <h2>Global Properties</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry private">
       <td class="access"></td>





  <a name="goog.events.KeyHandler.USES_KEYDOWN_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.events.KeyHandler.</span><span class="entryName">USES_KEYDOWN_</span>
        : <div class="fullType"><span class="type"><a href="http://www.google.com/url?sa=D&q=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean">boolean</a></span></div>
     </div>


     <div class="entryOverview">
       If true, the KeyEvent fires on keydown. Otherwise, it fires on keypress.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_events_keyhandler.js.source.html#line280">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>





  <a name="goog.events.KeyHandler.keyIdentifier_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.events.KeyHandler.</span><span class="entryName">keyIdentifier_</span>
        : <div class="fullType"><span class="type"><a href="http://www.google.com/url?sa=D&q=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span></div>
     </div>


     <div class="entryOverview">
       An enumeration of key identifiers currently part of the W3C draft for DOM3
and their mappings to keyCodes.
<a href="http://www.w3.org/TR/DOM-Level-3-Events/keyset.html#KeySet-Set">http://www.w3.org/TR/DOM-Level-3-Events/keyset.html#KeySet-Set</a>
This is currently supported in Safari and should be platform independent.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_events_keyhandler.js.source.html#line236">Code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry private">
       <td class="access"></td>





  <a name="goog.events.KeyHandler.mozKeyCodeToKeyCodeMap_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.events.KeyHandler.</span><span class="entryName">mozKeyCodeToKeyCodeMap_</span>
        : <div class="fullType"><span class="type"><a href="http://www.google.com/url?sa=D&q=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span></div>
     </div>


     <div class="entryOverview">
       Map from Gecko specific key codes to cross browser key codes
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_events_keyhandler.js.source.html#line268">Code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry private">
       <td class="access"></td>





  <a name="goog.events.KeyHandler.safariKey_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.events.KeyHandler.</span><span class="entryName">safariKey_</span>
        : <div class="fullType"><span class="type"><a href="http://www.google.com/url?sa=D&q=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span></div>
     </div>


     <div class="entryOverview">
       An enumeration of key codes that Safari 2 does incorrectly
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_events_keyhandler.js.source.html#line198">Code &raquo;</a>
  </td>
     </tr>


  </table>
</div>



      <!-- Column 1 end -->
    </div>

        <div class="col2">
          <!-- Column 2 start -->
          <div class="col2-c">
            <h2 id="ref-head">Directory events</h2>
            <div id="localView"></div>
          </div>

          <div class="col2-c">
            <h2 id="ref-head">File Reference</h2>
            <div id="sideFileIndex" rootPath="closure/goog" current="events/keyhandler.js"></div>
          </div>
          <!-- Column 2 end -->
        </div>
</div>
</div>

</body>
</html>
